/*----------------------------------------------------------------------------
 *      RL-ARM - RTX
 *----------------------------------------------------------------------------
 *      Name:    RTX_EX1.C
 *      Purpose: Your First RTX example program
 *----------------------------------------------------------------------------
 *      This code is part of the RealView Run-Time Library.
 *      Copyright (c) 2004-2013 KEIL - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

//#include <RTL.h>                      /* RTX kernel functions & defines      */
#include "os.h"
#include "string.h"
#include "stdio.h"

/*----------------------------------------------------------------------------
 *   release   and   take
 *---------------------------------------------------------------------------*/
int _mutex;
U64 stk_release[512/8];
 void task_release(void)
{
	_mutex = mutex_init();
	for(;;){
		mutex_unlock(_mutex);
		printf("release.\r\n");
		ssleep(1);

	}
}
 U64 stk_lock[512/8];
 void task_lock(void)
{
	for(;;){
		printf("lock.\r\n");
		mutex_lock(_mutex);
		tsleep(100);
	}
}

/*----------------------------------------------------------------------------
 *   init
 *---------------------------------------------------------------------------*/
U64 stk_init[512/8];	
 void task_init (void)
{
	os_task_create_user(task_release,23,stk_release,sizeof(stk_release));
	os_task_create_user(task_lock,23,stk_lock,sizeof(stk_lock));
	for(;;)
	{
		tsleep(1000);
	}
}




/*----------------------------------------------------------------------------
 *        Main: Initialize and start RTX Kernel
 *---------------------------------------------------------------------------*/

int main (void) {

	extern void InitConsoleWindow(void);
	extern void HideConsoleWindow(void);
	InitConsoleWindow();
	//HideConsoleWindow();
	
	os_task_create_user(task_init,0,stk_init,sizeof(stk_init));

	while(10){ssleep(1);}
	return 0;

}

/*----------------------------------------------------------------------------
 * end of file
 *---------------------------------------------------------------------------*/


